package com.douing.ad.dsp.bidding.rtb;

import java.util.Map;

public final class CalculationUtil {
    
    public static Long binSearch(Map<Long, Long[]> map, Long start, Long end, Long key) {   
        Long mid = Long.parseLong(((end - start) / 2 + start)+"") ;   
        if (map.get(mid)[1] <= key && map.get(mid)[2] >= key) {   
            return map.get(mid)[3];   
        }   
        if (start >= end) {   
            return 0l;   
        } else if (key > map.get(mid)[1]) {   
            return binSearch(map, mid + 1, end, key);   
        } else if (key < map.get(mid)[2]) {   
            return binSearch(map, start, mid - 1, key);   
        }   
        return 0l;   
    } 
       
}